#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

vector<long> P = {10, 100, 5, 50};
int n = P.size();
vector<vector<long>> m(n + 1, vector<long>(n + 1, 9999));

long RecurMatrixChain(vector<long> P, int i, int j)
{
    if (i == j)
    {
        m[i][j] = 0;
        return 0;
    }
    else
    {
        int k = i;
        for (; k < j; k++)
        {
            long q = RecurMatrixChain(P, i, k) + RecurMatrixChain(P, k + 1, j) + P[i - 1] * P[k] * P[j];
            if (q < m[i][j])
            {
                m[i][j] = q;
            }
        }
        return m[i][j];
    }
}

int main()
{
    cout << RecurMatrixChain(P, 1, 3);
}